from pydantic import BaseModel
from typing import List, Optional
from datetime import datetime

class FaultRecord(BaseModel):
    """故障记录模型"""
    id: int
    factory_name: str
    host_name: str
    fault_time: datetime
    alarm_name: str
    level: Optional[str] = None
    device_sn: Optional[str] = None
    resolution: Optional[str] = None
    recovery_time: Optional[datetime] = None
    note1: Optional[str] = None
    note2: Optional[str] = None

class FaultCreate(BaseModel):
    """创建故障记录模型"""
    factory_name: str
    host_name: str
    fault_time: datetime
    alarm_name: str
    level: Optional[str] = None
    device_sn: Optional[str] = None
    resolution: Optional[str] = None
    recovery_time: Optional[datetime] = None
    note1: Optional[str] = None
    note2: Optional[str] = None

class FaultUpdate(BaseModel):
    """更新故障记录模型"""
    factory_name: Optional[str] = None
    host_name: Optional[str] = None
    fault_time: Optional[datetime] = None
    alarm_name: Optional[str] = None
    level: Optional[str] = None
    device_sn: Optional[str] = None
    resolution: Optional[str] = None
    recovery_time: Optional[datetime] = None
    note1: Optional[str] = None
    note2: Optional[str] = None

class FaultStats(BaseModel):
    """故障统计模型"""
    total_count: int
    resolved_count: int
    unresolved_count: int

class ManufacturerStats(BaseModel):
    """厂家统计模型"""
    factory_name: str
    fault_count: int
    resolution: Optional[str] = None

class FaultTrend(BaseModel):
    """故障趋势模型"""
    date: str
    count: int

class AdvancedSearchRequest(BaseModel):
    """高级搜索请求模型"""
    factory_names: Optional[List[str]] = None
    host_names: Optional[List[str]] = None
    alarm_names: Optional[List[str]] = None
    start_date: Optional[str] = None
    end_date: Optional[str] = None
    status: Optional[str] = None  # "resolved" or "unresolved"
    page: int = 1
    size: int = 6